<?php

define('__PATH__', __DIR__);

session_start();

require_once __DIR__ . '/class/Db.class.php';

function M($name = '')
{
    if (empty($name)) {
        return false;
    }
    $dbObj = new Db($name);
    return $dbObj;
}

function display($name)
{
    global $pageTitle;
    global $caseListRow;
    global $case_list_id;
    global $messageList;
    $path = __PATH__ . '/template/' . $name . '.html';
    $tempPath = __PATH__ . '/temp/' . $name . '.php';
    $content = file_get_contents($path);
    $content = str_replace('__TEMPLATE__', '/template', $content);
    $content = str_replace('{%', '<?php echo $', $content);
    $content = str_replace('%}', '; ?>', $content);
    file_put_contents($tempPath, $content);
    include_once $tempPath;
}

function returnJson($code = 0, $msg = '', $data = '')
{
    $json = array(
        'code' => $code,
        'msg' => $msg,
        'data' => $data
    );
    die(json_encode($json));
}